<template>
  <el-container>
    <el-form  :model="hjxwbData"  label-position="right" label-width="100px" style="width:100%;text-align: center" ref="hjxwb" >
      <h3 :labelName="labelName">{{labelName}}</h3>
      <el-form-item label="物质编码" prop="1">
        <el-input v-model="hjxwbData.baseinfoWzbm"  :disabled="true"  ></el-input>
      </el-form-item>
      <el-form-item label="介质"  prop="2">
        <el-input v-model="hjxwbData.medium" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item label="单位"  prop="3">
        <el-input v-model="hjxwbData.unit" placeholder="请输入内容"></el-input>
      </el-form-item>
      <el-form-item label="值" prop="4">
        <el-input v-model="hjxwbData.value"   placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="终点" prop="5">
        <el-input v-model="hjxwbData.destination" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="试验时间" prop="6">
        <el-input v-model="hjxwbData.time" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="试验方法" prop="7">
        <el-input v-model="hjxwbData.method" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="实测/预测" prop="8">
        <el-input v-model="hjxwbData.shiceyuce" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item label="数据来源" prop="9">
        <el-input v-model="hjxwbData.source" placeholder="请输入内容" ></el-input>
      </el-form-item>
      <el-form-item label="备注" prop="10">
        <el-input v-model="hjxwbData.remark" placeholder="请输入内容"  ></el-input>
      </el-form-item>
      <el-form-item prop="11">
        <el-button type="primary" style="margin-top: 12px;" @click="method" :btName="btName">{{btName}}</el-button>
      </el-form-item>
    </el-form>
  </el-container>
</template>

<script>
    export default {
        name: "Hjxwb",
      props: {
        elementId: {
          type: String,
          default: ''
        },
        perms: '',
        labelName:'',
        btName:'',
        showdata:{}
      },
      data() {
        return {
          hjxwbData: {
            'id': '',
            'baseinfoWzbm': '',
            'attribute':'',
            'medium':'',
            'unit': '',
            'value': '',
            'destination': '',
            'time': '',
            'method':'',
            'shiceyuce': '',
            'source': '',
            'remark': '',
            'flag': '',
            'lastid': ''
          },
          findParams:{
            elementId:'',
            labelName:'',
            flag:''
          },
          addParams:{
            labelName:''
          },
          title:''
        }
      },
      watch: {
        elementId(value) {
        }
      },
      mounted() {
        console.log(this.btName)
        console.log('elementID:' + this.elementId)
        console.log(this.perms)
        //
        this.$nextTick(()=>{
          this.$refs['hjxwb'].resetFields()}
        )
        this.hjxwbData=this.showdata
      },
      methods: {
        // queryElement: function () {
        //   this.findParams.elementId=this.elementId
        //   this.findParams.labelName=this.labelName
        //   this.findParams.flag = 1
        //   this.$api.addrecord.findByIdAndFlagInHjxwb(this.findParams).then(res => {
        //     this.hjxwbData = res.data[0]
        //   })
        // },
        modifyId:function(){
          this.hjxwbData.id=this.perms+Date.now()
        },
        modifyAuthority:function(){
          if(this.perms==='admin'){
            this.hjxwbData.flag=1
          }else{
            if(this.btName ==="新增") {
              this.hjxwbData.flag=0
            }else{
              this.hjxwbData.flag=2
            }
          }
        },
        save:function() {
          this.modifyAuthority()
          this.addParams.labelName=this.labelName
          if(this.btName ==="新增") {
            this.modifyId()
            this.$api.addrecord.addRecordInHjxwb(this.hjxwbData, this.addParams).then(res => {
              alert("新增成功！")
            })
          } else{
            this.hjxwbData.lastid=this.hjxwbData.id
            this.modifyId()
            this.$api.addrecord.addRecordInHjxwb(this.hjxwbData, this.addParams).then(res => {
              alert("纠错成功！待审核")
            })
          }
        },
        update:function () {
          this.modifyAuthority()

          this.$api.addrecord.updateInHjxwb(this.hjxwbData).then(res => {
            alert("更新成功！")})
        },
        method:function () {
          if(this.btName==="更新"){
            this.update()
          }else {
            this.save()
          }
        }

      }
    }
</script>

<style scoped>

</style>
